package com.ss.android.article.base.feature.e;

import android.content.Context;
import android.support.design.a;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.app.AppData;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.lib.MobClickCombiner;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.json.JSONObject;

public final class m {
    public static a a;
    private Context b;
    private IWXAPI c;
    private AppData d;
    private static m e;
    private static final Object f;
    private long g;
    private static Class h;

    static {
        f = new Object();
    }

    private m(Context arg3) {

        this.g = 0;
        this.d = AppData.getInstance();
        this.b = arg3.getApplicationContext();
    }

    public final boolean a() {
        String v0_5;
        String v2;
        boolean v1;
        boolean v0_1;
        int v0;
        int v12 = 3;
        int v13 = 2;
        long v4 = 0;
        if (this.c != null) {
            if (this.g == v4 || System.currentTimeMillis() - this.g >= 1800000) {
                v0 = 1;
            } else {
                this.g = System.currentTimeMillis();
                v0 = 0;
            }

            if (v0 != 0) {
            } else {
                v0_1 = true;
                return v0_1;
            }
        }

        String v6 = this.d.cc;
        if (!a.isTextEmpty(v6)) {
            long v8 = System.currentTimeMillis();
            try {
                this.c = WXAPIFactory.createWXAPI(this.b, v6, true);
                v0_1 = this.c.registerApp(v6);
            } catch (Throwable v0_2) {
                v0_2.printStackTrace();
                this.c = null;
                v0_1 = false;
            }

            if (!v0_1) {
                this.c = null;
            }

            Logger.d("WeixinShareHelper", "init Wx: " + (System.currentTimeMillis() - v8));
            v1 = v0_1;
        } else {
            v1 = false;
        }

        boolean v9 = this.c != null ? true : false;
        if (!v9) {
            String v7 = AppLog.g(this.b);
            m.b();
            if (m.h == null) {
                v2 = "cannot get WXApiImplComm class";
            } else {
                Class v0_3 = m.h;
                Class[] v10 = new Class[v12];
                v10[0] = Context.class;
                v10[1] = String.class;
                v10[v13] = Boolean.TYPE;
                Object[] v11 = new Object[v12];
                v11[0] = this.b;
                v11[1] = "com.tencent.mm";
                v11[v13] = Boolean.TRUE;
                Object v0_4 = a.a(v0_3, "validateAppSignatureForPackage", v10, v11, new Object[0]);
                if ((v0_4 instanceof Boolean)) {
                    v0_5 = ((Boolean) v0_4).booleanValue() ? "validateAppSignature success" : "validateAppSignature failure";
                    v2 = v0_5;
                } else {
                    v2 = "validateAppSignatureForPackage doesnot return boolean type";
                }
            }

            v0_5 = v7 == null ? "failed_to_get_signature_hash" : "signature_hash " + v7;
            JSONObject v8_1 = new JSONObject();
            try {
                v8_1.put("validateAppSignatureResult", v2);
                v8_1.put("registerResult", v1);
                v8_1.put("signatureHash", v0_5);
                v8_1.put("wxAppId", v6);
            } catch (Exception v0_6) {
                v0_6.printStackTrace();
            }

            MobClickCombiner.onEvent(this.b, "weixin_share", "wei_share_check", v4, v4, v8_1);
        }

        return v9;
    }

    public static m a(Context arg2) {
        Object v1 = m.f;
        synchronized (v1) {
            if (m.e == null) {
                m.e = new m(arg2);
            }
        }
        return m.e;
    }

    public static String a(int arg1) {
        String v0 = arg1 == 0 ? "share_weixin" : "share_weixin_moments";
        return v0;
    }

    private static void b() {
        Class v1 = m.class;
        synchronized (v1) {
            if (m.h == null) {
                try {
                    m.h = Class.forName("com.tencent.mm.sdk.openapi.WXApiImplComm");
                } catch (Exception e) {

                }
            }
        }
    }
}

